package com.kingyea.app.market.Dictionary.controller;

import com.kingyea.app.market.Dictionary.bean.Dictionary;
import com.kingyea.app.market.Dictionary.service.DictionaryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author
 * @version v1.0.0
 * @description Dictionary 控制层
 * @date Created in 2018-02-23 17:02:59
 */
@RequestMapping(value = "/dictionary")
@RestController
public class DictionaryController {

    private static final Logger LOGGER = LoggerFactory.getLogger(DictionaryController.class);

    @Autowired
    private DictionaryService dictionaryService;

    /**
     * 查询全部
     *
     * @param
     * @return
     */
    @RequestMapping(method = RequestMethod.GET)
    public List<Dictionary> list() throws Exception {
        return dictionaryService.list(null);
    }

    /**
     * 通过ID查找对象
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public Dictionary detail(@PathVariable Integer id) throws Exception {
        return dictionaryService.getById(id);
    }

    /**
     * 创建
     *
     * @param dictionary
     * @return
     */
    @RequestMapping(method = RequestMethod.POST)
    public Dictionary create(@RequestBody Dictionary dictionary) throws Exception {
        return dictionaryService.save(dictionary);
    }

    /**
     * 更新
     *
     * @param dictionary
     * @return
     */
    @RequestMapping(method = RequestMethod.PUT)
    public Dictionary update(@RequestBody Dictionary dictionary) throws Exception {
        return dictionaryService.update(dictionary);
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
    public int delete(@PathVariable Integer id) throws Exception {
        return dictionaryService.deleteById(id);
    }

}
